/**
 * 
 */
package com.idea.zd.sys.service;
import java.util.List;

import com.idea.zd.sys.model.Role;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.server.BaseService;

/**
 * @author y.z
 */
public class RoleService extends BaseService<Role> {
	
	/**
	 * 获取角色分页
	 * @param curPage
	 * @return
	 */
	public Page<Role> getPage(int curPage){
		return super.getPage(curPage, "select *", " from sys_role order by create_date desc ");
	}
	
	
	/**
	 * 获取所有角色
	 * @return
	 */
	public List<Role> getList(){
		return super.find("select * from sys_role order by create_date desc");
	}
	
	
	
	/**
	 * 保存角色
	 * @param dictionary
	 * @return
	 */
	public boolean add(Role role){
		return super.save(role);
	}
	
	/**
	 * 更新角色
	 * @param dictionary
	 * @return
	 */
	public boolean update(Role role){
		return super.update(role);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	public Role getById(int id){
		return super.findById(id);
	}
	
	/**
	 * 删除角色
	 * @param id
	 * @return
	 */
	public boolean del(int id){
		boolean flag = false;
		
		if(null != super.findFirst("select * from sys_role_per where role_id = "+id+"")){
			
			if(super.update("delete from sys_role_per where where role_id = "+id+"")){
				
				if(super.delById(id)){
					flag = true;
				}
			}
		}else{
			flag = super.delById(id);
		}
		
		return flag;
	}
	
}
